#
# "@(#) $Id: Settings.py,v 1.1.1.1 2006-07-27 03:16:08 gioshe Exp $"
#
# This work is released under the GNU GPL, version 2 or later.
#
from PListParser import *
from Paths import *
import time

class Settings:
	def __init__(self):
		self.data = {}
		if not self.readXMLFile():
			self.setDefaults()
	
	def filePath(self):
		return library("Settings.xml")

	def readXMLFile(self):
		#FIXME GTD:: needs a better way of getting the path
		#return False
		filePath = self.filePath()
		if os.path.exists(filePath):
			try:
				print "reading settings"
				reader = PListReader()
				print "Settings:: plistparser reading",filePath
				self.data = reader.parse(filePath)[0]
				print self.data
				return True
			except: 
				pass
		return False
		
	def writeXMLFile(self):
		#print "writing settings"
		self.data['Modified'] = time.gmtime(time.time())
		writer = PListWriter()
		writer.unparse([self.data],self.filePath())

	def setDefaults(self):
		import traceback
		traceback.print_stack()
		self.data['Version'] = '1.0'
		self.data['Managed'] = False
		self.data['Modify Tags'] = False
		self.data['Encoder'] = 'mp3'
		self.data['Encoder Bit Rate'] = 192000
		self.data['CD Insertion Action'] = 'show'
		self.data['CD Error Correction'] = False
		self.data['Volume'] = 50
		self.data['Show Title']=True
		self.data['Show Time']=True
		self.data['Show Artist']=True
		self.data['Show Album']=True
		self.data['Show Genre']=True
		self.data['Show Rating']=False
		self.data['Show Count']=False
		self.data['Show Last Played']=False
		self.data['ColorR']=180
		self.data['ColorG']=194
		self.data['ColorB']=219
		
	def static_singleton():
		global _settingsSingleton
		if _settingsSingleton==None:
			_settingsSingleton = Settings()
		return _settingsSingleton
	singleton = staticmethod(static_singleton)
	
	def static_settings():
		return Settings.singleton().data
	settings = staticmethod(static_settings)
	
	def get(self,entry): return self.data[entry]

_settingsSingleton = None
